package com.example.administrator.myapplication.activity.anchorSecondActivity;

import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.android.databinding.library.baseAdapters.BR;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.activity.anchorSecondActivity.bean.AnchorSecondAvtivityAblumData;
import com.example.administrator.myapplication.activity.anchorSecondActivity.bean.AnchorSecondAvtivityAblumEntity;
import com.example.administrator.myapplication.callback.XmlyService;
import com.example.administrator.myapplication.databinding.ActivityAnchorAblumSecondBinding;
import com.example.administrator.myapplication.databinding.ActivityAnchorSecondBinding;
import com.example.administrator.myapplication.until.BaseApplication;
import com.example.administrator.myapplication.until.CommentRecyclerAdapter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AnchorAblumActivity extends AppCompatActivity implements Callback<AnchorSecondAvtivityAblumEntity> {
   private ActivityAnchorAblumSecondBinding binding;
    private CommentRecyclerAdapter<Object> adapter;
    private XmlyService service;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       binding = DataBindingUtil.setContentView(this,R.layout.activity_anchor_ablum_second);
        aboutRecycler();
    }

    private void aboutRecycler() {
        String uid = getIntent().getStringExtra("uid");
        adapter = new CommentRecyclerAdapter<>(this,new ArrayList<>(), R.layout.anchorsecondactivity_album_item, BR.anchorSecondAvtivityAblumData);
          binding.recycler.setAdapter(adapter);
        service = ((BaseApplication) getApplicationContext()).getService();
        service.getAnchorSecondAvtivityAblumEntity(uid).enqueue(this);
    }

    @Override
    public void onResponse(Call<AnchorSecondAvtivityAblumEntity> call, Response<AnchorSecondAvtivityAblumEntity> response) {
          adapter.addAll(response.body().getList());
    }

    @Override
    public void onFailure(Call<AnchorSecondAvtivityAblumEntity> call, Throwable t) {
        Toast.makeText(this, "AnchorAblumActivity" + t.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
